package com.jinghang.wayofrich.common;

import android.graphics.Color;
import android.support.design.widget.AppBarLayout;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import com.jinghang.wayofrich.R;

/**
 * 通用顶部菜单
 */
public class HeadBar {
    private View mFLayout;
    private TextView mTextView;
    public void commonHeadBar(View view){
        AppBarLayout mAppBarLayout = view.findViewById(R.id.appbar);
        mFLayout = view.findViewById(R.id.fl_layout);
        mTextView = view.findViewById(R.id.appname);
        mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                int toolbarHeight = appBarLayout.getTotalScrollRange();
                int dy = Math.abs(verticalOffset);
                if (dy <= toolbarHeight) {
                    float scale = (float) dy / toolbarHeight;
                    float alpha = scale * 255;
                    mFLayout.setBackgroundColor(Color.argb((int) alpha, 221, 0, 27));
                    mTextView.setGravity(Gravity.CENTER);
                    mTextView.setTextColor(Color.argb((int) alpha, 255, 255, 255));
                    mTextView.setText("生财有道");
                }
            }
        });
    }
}
